<script setup lang="ts">
import { ref } from "vue";
import { formRules } from "./utils/rule";
import { FormProps } from "./utils/types";
import { usePublicHooks } from "@/views/system/hooks";
import { Codemirror } from "vue-codemirror";
import { sql } from "@codemirror/lang-sql";

const extensions = [sql()];
const props = withDefaults(defineProps<FormProps>(), {
  formInline: () => ({
    id: 0,
    tempName: "",
    tempCode: "",
    tempContext: "",
    tempHtml: "",
    disate: ""
  })
});
usePublicHooks();
const ruleFormRef = ref();
const newFormInline = ref(props.formInline);

function getRef() {
  return ruleFormRef.value;
}
defineExpose({ getRef });
</script>

<template>
  <el-form
    ref="ruleFormRef"
    :model="newFormInline"
    :rules="formRules"
    label-width="82px"
  >
    <el-form-item label="模板名称" prop="tempName">
      <el-input
        v-model="newFormInline.tempName"
        clearable
        placeholder="请输入微信消息模板名称"
      />
    </el-form-item>

    <el-form-item label="模板CODE" prop="tempCode">
      <el-input
        v-model="newFormInline.tempCode"
        clearable
        placeholder="请输入模板code"
      />
    </el-form-item>
    <el-form-item label="模板文本" prop="tempContext">
      <div class="box">
        <Codemirror
          class="code"
          v-model="newFormInline.tempContext"
          :style="{ height: '100%' }"
          :extensions="extensions"
          :autofocus="true"
          :disabled="false"
        />
      </div>
    </el-form-item>
    <el-form-item label="模板HTML" prop="tempHtml">
      <div class="box">
        <Codemirror
          class="code"
          v-model="newFormInline.tempHtml"
          :style="{ height: '100%' }"
          :extensions="extensions"
          :autofocus="true"
          :disabled="false"
        />
      </div>
    </el-form-item>
  </el-form>
</template>
<style>
.box {
  width: 100%;
  height: 300px;
  border: 1px solid rgb(185 182 182);
}

.code {
  width: 300px;
  height: 100%;
  font-size: 18px;
}
</style>
